package com.wrl.proxy.cglibProxy;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.time.LocalDateTime;

public class LogInterceptor implements MethodInterceptor {


    @Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
        before();

        Object o = proxy.invokeSuper(obj, args);

        after();
        return o;
    }

    /**
     * 调用方法之前执行
     */
    private void before() {
        System.out.println("log start time " + LocalDateTime.now());
    }

    /**
     * 调用方法之后执行
     */
    private void after() {
        System.out.println("log end time " + LocalDateTime.now());
    }
}
